package com.jerry.template.module.mainpage.shouye.image.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.jerry.template.module.mainpage.shouye.image.entity.ImageMessage;
import com.jerry.template.utils.ImageUtils;

import java.util.List;

/**
 * Created by chenhuan on 2016/5/10.
 */
public class ImageGridViewAdapter extends BaseAdapter{
    private List<ImageMessage.DataBean.DataBean1.GroupBean.LargeImageList> data;
    private Context context;
    private  Bitmap bitmap;

    public ImageGridViewAdapter(List<ImageMessage.DataBean.DataBean1.GroupBean.LargeImageList> data, Context context){
        this.data = data;
        this.context = context;

        for(int i = 0; i < data.size() ; i++){
            bitmap = ImageUtils.getBitmapFromUrl(data.get(i).getUrl(), 10 * 1000);
        }
    }



    @Override
    public int getCount(){
        return data == null ? 0: data.size();
    }

    @Override
    public ImageMessage.DataBean.DataBean1.GroupBean.LargeImageList getItem(int position){
        return data.get(position);
    }

    @Override
    public long getItemId(int position){
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(75, 75));//设置ImageView对象布局
            imageView.setAdjustViewBounds(false);//设置边界对齐
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);//设置刻度的类型
            imageView.setPadding(8, 8, 8, 8);//设置间距

        }
        else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageBitmap(bitmap);
        return imageView;
    }
}
